<?php
namespace app\serverintegralmall\service\goods;
use \app\manage\service\ApiBase;
/**
 * @author:      李颖
 * @DateTime:    2017-10-27 17:46:42
 * @Description: 积分商城 - 商品分类
 */
class GoodsCategory extends ApiBase{
	

	protected $goodsCategoryLogic = '\app\serverintegralmall\logic\GoodsCategory';
    protected $goodsCategoryValidate = '\app\serverintegralmall\validate\GoodsCategory';

	use \app\servergoods\traits\BaseCheckCate;
    //添加或修改商品分类
    private function _updateGoodsCate(bool $isEdit)
    {
        $data = $isEdit ? $this->issetReceiveData(['app_id'=>'','other_app_read'=>'','is_public'=>0,'name'=>' ','id'=>0,'profile_pic'=>'','keywords'=>'','description'=>'','order'=>100]) : $this->receiveData(['app_id'=>'','other_app_read'=>'','is_public'=>0,'name'=>' ', 'pid'=>0,'profile_pic'=>'','keywords'=>'','description'=>'','order'=>100]);

        $checkData = $this->_baseCheckCate($data, '', 'edit', $this->goodsCategoryValidate, $this->goodsCategoryLogic, 'dbOneCateInfo');
        if($checkData['status'] != SUCCESS_STATUS){
            return $checkData;
        }
        if(isset($data['id'])){
            $res = $this->logic($this->goodsCategoryLogic)->editGoodsCate($data);
        }else{
            $data['level'] = $data['pid'] ? $checkData['res']['level'] + 1 : 0;
            $res = $this->logic($this->goodsCategoryLogic)->addGoodsCate($data);
        }
        return $res;
    }
	//添加商品分类
    public function addGoodsCate()
    {
        return $this->_updateGoodsCate(false);
    }
    //编辑商品分类
    public function editGoodsCate()
    {
        return $this->_updateGoodsCate(true);
    }
    //后台获取某商品分类的详细信息
    public function oneCateInfo(): array
    {
        $data = $this->issetReceiveData(['id'=>0,'app_id'=>0]);
        return $this->stepRun($data, 'oneCateInfo','oneCateInfo');
    }
    /*
        根据id数组 启用/禁用一个或多个分类
        父类被禁用，则其所有子类也被禁用，开启同理
    */
    public function changeCateStatus(): array
    {
        $data = $this->issetReceiveData(['id'=>0,'status'=>' ','app_id'=>'']);
        return $this->stepRun($data, 'changeCateStatus','changeCateStatus');
    }
    //获取商品分类列表
    public function goodsCateList(): array
    {
        $data = $this->haveIssetReceiveData(['id'=>0,'app_id'=>0]);
        return $this->stepRun($data,'goodsCateList','goodsCateList');
    }
    //删除一个或多个商品分类
    public function delCate(): array
    {
        $data = $this->issetReceiveData(['id'=>[],'app_id'=>0]);
        return $this->stepRun($data,'delCate','delCate');
    }










}